{include file="public/head" /}
<style>input[name='keyword']{width: 210px}</style>
</head>
<body>
{include file="public/top" /}
<div class="am-cf admin-main">
    {include file="public/nav" /}

    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">报名信息查看</strong></div>

            </div>

            <div class="am-u-md-12">
                <div class="am-btn-toolbar">
                    <div class="am-u-sm-12 am-u-md-6">
                        <form method="post" action="/admin/Signup/signupLog">
                            <div class="am-form-group">
                                <input type="text" name="keyword" value="{:input('request.keyword')}" placeholder="按项目,姓名搜索">
                                <button type="submit" class="am-btn am-btn-secondary am-btn-xs">搜索</button>
                                <a href="/admin/Signup/signupLog" class="am-btn am-btn-danger am-btn-xs">重置</a>
                            </div>
                            <a href="javascript:;" class="am-btn am-btn-danger am-btn-xs"
                               id="excell" onclick="method5('dataTable')">导出表格</a>
                        </form>
                    </div>
                </div>
                <table class="am-table am-table-bordered am-table-radius am-table-striped" id="dataTable">
                    <thead>
                    <tr>
                        <th>项目名称</th>
                        <th>姓名</th>
                        <th>用户名</th>
                        <th>性别</th>
                        <th>手机</th>
                        <th>身份证号</th>
                        <th>出生日期</th>
                        <th>报名时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {php}$Sex = ['男','女','未设置'];{/php}
                    {volist name="rows" id="vo"}
                    <tr>
                        <td>{$vo.item_name}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.username}</td>
                        <td>{$Sex[$vo.sex]}</td>
                        <td>{$vo.mobile}</td>
                        <td>{$vo.id_card}</td>
                        <td>{$vo.birthday}</td>
                        <td>{$vo.create_time}</td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-danger" onclick="del(this,{$vo.id})">移除</button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <div class="pagination" style="float: right">{$page}</div>
            </div>
        </div>
    </div>
</div>
<!-- content end -->
</div>
<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>
<script>
    function del(self,id) {
        layer.confirm('确认要移除吗?', function (index) {
            $.post("{:url('admin/Signup/quit')}", {id: id}, function (res) {
                if (res.code == 1) {
                    $(self).closest("tr").remove();//前端删除
                    layer.msg(res.msg, {time: 1500, icon: 6});
                    var keyword = $("input[name='keyword']").val();
                    setTimeout(function () {
                        window.location.href = '/admin/signup/signupLog/keyword/'+keyword;
                    },1000);
                } else {
                    layer.msg(res.msg, {time: 1500, icon: 5});
                }
            });
        });
    }
    //打印表格
    var idTmr;

    function getExplorer() {
        var explorer = window.navigator.userAgent;
        //ie
        if(explorer.indexOf("MSIE") >= 0) {
            return 'ie';
        }
        //firefox
        else if(explorer.indexOf("Firefox") >= 0) {
            return 'Firefox';
        }
        //Chrome
        else if(explorer.indexOf("Chrome") >= 0) {
            return 'Chrome';
        }
        //Opera
        else if(explorer.indexOf("Opera") >= 0) {
            return 'Opera';
        }
        //Safari
        else if(explorer.indexOf("Safari") >= 0) {
            return 'Safari';
        }
    }

    function method5(tableid) {
        if(getExplorer() == 'ie') {
            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            var oWB = oXL.Workbooks.Add();
            var xlsheet = oWB.Worksheets(1);
            var sel = document.body.createTextRange();
            sel.moveToElementText(curTbl);
            sel.select();
            sel.execCommand("Copy");
            xlsheet.Paste();
            oXL.Visible = true;

            try {
                var fname = oXL.Application.GetSaveAsFilename("Excel.xls",
                    "Excel Spreadsheets (*.xls), *.xls");
            } catch(e) {
                print("Nested catch caught " + e);
            } finally {
                oWB.SaveAs(fname);
                oWB.Close(savechanges = false);
                oXL.Quit();
                oXL = null;
                idTmr = window.setInterval("Cleanup();", 1);
            }

        } else {
            tableToExcel(tableid)
        }
    }

    function Cleanup() {
        window.clearInterval(idTmr);
        CollectGarbage();
    }
    var tableToExcel = (function() {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html><head><meta charset="UTF-8"></head><body><table  border="1">{table}</table></body></html>',
            base64 = function(
                s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            },
            format = function(s, c) {
                return s.replace(/{(\w+)}/g, function(m, p) {
                    return c[p];
                })
            }
        return function(table, name) {
            if(!table.nodeType)
                table = document.getElementById(table)
            var ctx = {
                worksheet: name || 'Worksheet',
                table: table.innerHTML
            }
            window.location.href = uri + base64(format(template, ctx))
        }
    })()
</script>
</body>
</html>
